package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.Order;
import jakarta.annotation.Resource;
import java.util.List;
import org.apache.ibatis.annotations.Select;

/**
 * 订单表(Order)表数据库访问层
 *
 * @author 游家纨绔
 * @since 2023-09-09 19:40:00
 */
public interface OrderMapper extends BaseMapper<Order> {

	@Select("""
			SELECT o.id, o.subject, o.order_no, o.total_amount, o.create_time, o.update_time,
			       (SELECT tdi.item_text AS text FROM `pay_dict` td JOIN `pay_dict_item` tdi ON td.id = tdi.dict_id WHERE td.dict_code = 'ORDER_STATUS' and tdi.item_value = o.status) AS status,
			       (SELECT tdi.item_text AS text FROM `pay_dict` td JOIN `pay_dict_item` tdi ON td.id = tdi.dict_id WHERE td.dict_code = 'PAY_METHOD' and tdi.item_value = o.pay_type) AS pay_type
			FROM `pay_order` o
			""")
	@Resource(type = List.class)
	List<Order> selectDictAll();

}
